import {$loadSaleDataSet} from "../../../services/statementService";

export function loadSaleReportDataSet(start,end){
  return $loadSaleDataSet(start,end);
}
export const GetOption={
  LINE:(dataSet)=>{
    const dataSource=dataSet;
    const legendData=dataSet[0].slice(1);
    const seriesConfig=legendData.map(item=>{
      if(item!='product'){
        return {
          type:'line',
          markLine: {
            data: [{
              type: "average",
              name: "Avg"
            }]
          }
        };
      }
    })
    console.log(legendData)
    console.log(JSON.stringify(dataSource))
    let _option={
      tooltip:{
        trigger: 'axis',
        //formatter:'{b}<br/>{a}:{c}￥',
      },
      toolbox:{
        show:true,
        showTitle:true,
        feature: {
          dataZoom: {
            yAxisIndex: "none"
          },
          dataView: {
            readOnly: false,
            optionToContent: function(opt) {
              let ds = opt.dataset[0].source;
              let legend=ds[0];
              let data=ds.slice(1);
              let table = '<table style="width:100%;text-align:center"><tbody><tr>'
                + '<td>时间</td>';
              //表头
              for(let i=1;i<legend.length;i++){
                table+=
                  '<td>' + legend[i] + '</td>'
              }
              table+='</tr>';
              //表数据
              for (let i = 0, l = data.length; i < l; i++) {
                table += '<tr>';
                for(let j=0;j<legend.length;j++){
                  table+='<td>' + data[i][j] + '</td>'
                }
                table+='</tr>';
              }
              table += '</tbody></table>';
              return table;
            }
          },
          magicType: {
            type: ["line", "bar"]
          },
          restore: {},
        }
      },
      legend:{},
      dataset:{
        source:dataSource,
      },
      xAxis:{
        type:'category'
      },
      yAxis:{},
      //series:[
      //  {type:'line'},
      //]
      series:seriesConfig
    };
    console.log(_option)
    return _option;
  }
}
